using Infrastructure.Attribute;
using Infrastructure.Extensions;
using ZR.Model.Business.Dto;
using ZR.Model.Business;
using ZR.Repository;
using ZR.Service.Business.IBusinessService;

namespace ZR.Service.Business
{
    /// <summary>
    /// 部门配置表Service业务层处理
    /// </summary>
    [AppService(ServiceType = typeof(IDeptService), ServiceLifetime = LifeTime.Transient)]
    public class DeptService : BaseService<Dept>, IDeptService
    {
        /// <summary>
        /// 查询部门配置表列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public PagedInfo<DeptDto> GetList(DeptQueryDto parm)
        {
            var predicate = QueryExp(parm);

            var response = Queryable()
                .Where(predicate.ToExpression())
                .ToPage<Dept, DeptDto>(parm);

            return response;
        }


        /// <summary>
        /// 获取详情
        /// </summary>
        /// <param name="DeptId"></param>
        /// <returns></returns>
        public Dept GetInfo(long DeptId)
        {
            var response = Queryable()
                .Where(x => x.DeptId == DeptId)
                .First();

            return response;
        }

        /// <summary>
        /// 添加部门配置表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public Dept AddDept(Dept model)
        {
            return Insertable(model).ExecuteReturnEntity();
        }

        /// <summary>
        /// 修改部门配置表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int UpdateDept(Dept model)
        {
            return Update(model, true);
        }

        /// <summary>
        /// 查询导出表达式
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        private static Expressionable<Dept> QueryExp(DeptQueryDto parm)
        {
            var predicate = Expressionable.Create<Dept>();

            return predicate;
        }
    }
}